package bar.dark.lee.setting.sms.smsinsert;

import java.util.Calendar;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import bar.dark.lee.BDConstents;
import bar.dark.lee.common.BDUtil;
import bar.dark.lee.setting.sms.InputData;

public class SmsOutMoney4 
{
	private int smsType; 
//	private boolean flagATM = false;
//	private boolean flagHalbu = false;
//	private String halbuMonth = "0";
//	
//	private boolean FLAG = true;
	private boolean available = false;
//	
//	private boolean outmoneyFlag = false;
//	
//	//1:check 2:credit
	private int checkcreditFlag = 0;
//	
	private final int CHECK = 1;
	private final int CREDIT = 2;
//	
	private String message;
	private InputData data;
//	
	private String date;
	
	public SmsOutMoney4(){};
	
	public SmsOutMoney4(InputData data, String message, String date, int smsType, int checkcreditFlag)
	{
		this.data = data;
		this.message = message;
		this.date = date;
		this.smsType = smsType;
		this.checkcreditFlag = checkcreditFlag;
		
		outMoney();
	}
	
	public boolean getAvailable()
	{
		return available;
	}
	
	public InputData getData()
	{
		return data;
	}
	
	public int getSmsType()
	{
		return smsType;
	}
	
	private void outMoney()
	{
		if ( (data.getName().indexOf("광주은행") != -1) )
		{
			/*
			 * 광주은행 후불교통카드 결제금액통지 953003XX00XXX630 01월28일 12,870원
			 */
			Pattern pName = Pattern.compile("(\\d{3,}X{1,}\\d{1,}X{1,}\\d{1,})\\s+");
			Matcher mName = pName.matcher(message);
			Pattern pMoney = Pattern.compile("(\\d*,*\\d*,*\\d*,*\\d)원");
			Matcher mMoney = pMoney.matcher(message);
			Pattern pDate = Pattern.compile("(\\d{1,2})월(\\d{1,2})일");
			Matcher mDate = pDate.matcher(message);
//			Pattern pMemo = Pattern.compile("\\d*,*\\d*,*\\d*,*\\d원(.+\\s*.+)\\.누적액");
//			Matcher mMemo = pMemo.matcher(message);
//			Pattern pMemo2 = Pattern.compile("\\d{1,2}:\\d{1,2}\\.(.+$)");
//			Matcher mMemo2 = pMemo2.matcher(message);
			
			if (mName.find())
			{
				for (int i=0; i<mName.groupCount(); i++) 
				{
					data.setName("광주은행(" + (mName.group(1)) + ")");
				}
			}
			else
			{
				available = false;
				return;
			}
			
			if (mMoney.find()) 
			{
				for (int i=0; i<mMoney.groupCount(); i++) 
				{
					data.setMoney((mMoney.group(1).replaceAll(",", "")));
				}
			}
			else
			{
				available = false;
				return;
			}
			
			Calendar calendar = Calendar.getInstance();
			if (date != null && date.length() > 0)
			{
				if (mDate.find())
				{
					//data.setDate(date);
					data.setDate(date.substring(0, 4) + mDate.group(1) + mDate.group(2));
				}
			} 
			else if (mDate.find()) 
			{
				for (int i=0; i<mDate.groupCount(); i++) 
				{
					data.setDate(calendar.get(Calendar.YEAR)+(mDate.group(1) + mDate.group(2)));
				}
			}
			else
			{
				available = false;
				return;
			}
//			else
//			{
//				data.setDate(BDUtil.getDateDB(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH)+1, calendar.get(Calendar.DAY_OF_MONTH)));
//			}
			
//			if (mMemo.find()) 
//			{
//				for (int i=0; i<mMemo.groupCount(); i++) 
//				{
					data.setMemo1("광주은행 후불교통카드 " + mDate.group(1) + "월" + mDate.group(2) + "일");
					data.setMemo2("광주은행 후불교통카드 " + mDate.group(1) + "월" + mDate.group(2) + "일");
					data.setMemo3("광주은행 후불교통카드 " + mDate.group(1) + "월" + mDate.group(2) + "일");
					data.setMemo4("광주은행 후불교통카드 " + mDate.group(1) + "월" + mDate.group(2) + "일");
//				}
//			}
//			else if (mMemo2.find()) 
//			{
//				for (int i=0; i<mMemo2.groupCount(); i++) 
//				{
//					data.setMemo1((mMemo2.group(1)));
//					data.setMemo2((mMemo2.group(1)));
//					data.setMemo3((mMemo2.group(1)));
//					data.setMemo4((mMemo2.group(1)));
//				}
//			}
//			else
//			{
//				available = false;
//				return;
//			}
			
			available = true;
		}
		else if ( (data.getName().equalsIgnoreCase("광주") ) )
		{
			/*
			 * 광주 05/23 18:56[184-107-XXX629]출         5,000잔     2,188,937  에이원
			 */
			Pattern pName = Pattern.compile("\\d{2}:\\d{2}\\[(\\d{1,}-\\d{1,}-.+)\\]출");
			Matcher mName = pName.matcher(message);
			Pattern pMoney = Pattern.compile("(\\d*,*\\d*,*\\d*,*\\d)잔");
			Matcher mMoney = pMoney.matcher(message);
			Pattern pDate = Pattern.compile("(\\d{2}/\\d{2})");
			Matcher mDate = pDate.matcher(message);
			Pattern pMemo = Pattern.compile("잔.*\\d*,*\\d*,*\\d*,*\\d\\s+(.+)");	// ???원 뒤에
			Matcher mMemo = pMemo.matcher(message);
			
			if (mName.find())
			{
				for (int i=0; i<mName.groupCount(); i++) 
				{
					data.setName(data.getName() + "(" + (mName.group(1)).replaceAll("-", "") + ")");
				}
			}
			else
			{
				available = false;
				return;
			}
			
			if (mMoney.find()) 
			{
				for (int i=0; i<mMoney.groupCount(); i++) 
				{
					data.setMoney((mMoney.group(1).replaceAll(",", "")));
				}
			}
			else
			{
				available = false;
				return;
			}
			
			Calendar calendar = Calendar.getInstance();
			if (date != null && date.length() > 0)
			{
				data.setDate(date);
			} 
			else if (mDate.find()) 
			{
				for (int i=0; i<mDate.groupCount(); i++) 
				{
					data.setDate(calendar.get(Calendar.YEAR)+(mDate.group(1).replaceAll("/", "")));
				}
			}
			else
			{
				data.setDate(BDUtil.getDateDB(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH)+1, calendar.get(Calendar.DAY_OF_MONTH)));
			}
			
			if (mMemo.find()) 
			{
				for (int i=0; i<mMemo.groupCount(); i++) 
				{
					data.setMemo1((mMemo.group(1)));
					data.setMemo2((mMemo.group(1)));
					data.setMemo3((mMemo.group(1)));
					data.setMemo4((mMemo.group(1)));
				}
			}
			else
			{
				available = false;
				return;
			}
			
			available = true;
		}
		else if ( (data.getName().equalsIgnoreCase("W") ) )
		{
			Pattern pMoney = Pattern.compile("(\\d*,*\\d*,*\\d*,*\\d)원");
			Matcher mMoney = pMoney.matcher(message);
			Pattern pDate = Pattern.compile("([\\d]{2}[/][\\d]{2})");
			Matcher mDate = pDate.matcher(message);
			Pattern pMemo = Pattern.compile("\\d{2}:\\d{2}(.+)\\s*");	// ???원 뒤에
			Matcher mMemo = pMemo.matcher(message);
			
			if (mMoney.find()) 
			{
				for (int i=0; i<mMoney.groupCount(); i++) 
				{
					data.setMoney((mMoney.group(1).replaceAll(",", "")));
				}
			}
			else
			{
				available = false;
				return;
			}
			
			Calendar calendar = Calendar.getInstance();
			if (date != null && date.length() > 0)
			{
				data.setDate(date);
			} 
			else if (mDate.find()) 
			{
				for (int i=0; i<mDate.groupCount(); i++) 
				{
					data.setDate(calendar.get(Calendar.YEAR)+(mDate.group(1).replaceAll("/", "")));
				}
			}
			else
			{
				data.setDate(BDUtil.getDateDB(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH)+1, calendar.get(Calendar.DAY_OF_MONTH)));
			}
			
			if (mMemo.find()) 
			{
				for (int i=0; i<mMemo.groupCount(); i++) 
				{
					data.setMemo1((mMemo.group(1)));
					data.setMemo2((mMemo.group(1)));
					data.setMemo3((mMemo.group(1)));
					data.setMemo4((mMemo.group(1)));
				}
			}
			else
			{
				available = false;
				return;
			}
			
			available = true;
		}
		else if ( (data.getName().indexOf("부산") != -1) )
		{
			/*
			 * 부산07/16 14:41 273-12-0***03-0 오카모카 (부산) 출금3,000 잔액149,715
				부산07/30 12:04 101-**-******-* (주)롯데리아부산서 (부산) 출금3,000 잔액195,417
				부산01/29 16:03 112-2031-***6-08 롯데쇼핑(주)롯데슈 (부산) 출금12,810
				
				부산07/15 14:09 112-2029-***0-01 (0358)카드 (부산) 입금60,000 잔액60,000
			 */
			Pattern pName = Pattern.compile("\\d{2}:\\d{2}\\s+(.+)\\s+");
			Matcher mName = pName.matcher(message);
			Pattern pMoney = Pattern.compile("출금(\\d*,*\\d*,*\\d*,*\\d)");
			Matcher mMoney = pMoney.matcher(message);
			Pattern pDate = Pattern.compile("([\\d]{2}[/][\\d]{2})");
			Matcher mDate = pDate.matcher(message);
			Pattern pMemo = Pattern.compile("-.{1,3}\\s+(.+)\\s+출금");	// ???원 뒤에
			Matcher mMemo = pMemo.matcher(message);
			
			if (mName.find())
			{
				for (int i=0; i<mName.groupCount(); i++) 
				{
					data.setName("부산" + "(" + ((mName.group(1)).replace("-", "").substring(0, 10)) + ")");
				}
			}
			else
			{
				available = false;
				return;
			}
			
			if (mMoney.find()) 
			{
				for (int i=0; i<mMoney.groupCount(); i++) 
				{
					data.setMoney((mMoney.group(1).replaceAll(",", "")));
				}
			}
			else
			{
				available = false;
				return;
			}
			
			Calendar calendar = Calendar.getInstance();
			if (date != null && date.length() > 0)
			{
				data.setDate(date);
			} 
			else if (mDate.find()) 
			{
				for (int i=0; i<mDate.groupCount(); i++) 
				{
					data.setDate(calendar.get(Calendar.YEAR)+(mDate.group(1).replaceAll("/", "")));
				}
			}
			else
			{
				data.setDate(BDUtil.getDateDB(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH)+1, calendar.get(Calendar.DAY_OF_MONTH)));
			}
			
			if (mMemo.find()) 
			{
				for (int i=0; i<mMemo.groupCount(); i++) 
				{
					data.setMemo1((mMemo.group(1)));
					data.setMemo2((mMemo.group(1)));
					data.setMemo3((mMemo.group(1)));
					data.setMemo4((mMemo.group(1)));
				}
			}
			else
			{
				available = false;
				return;
			}
			
			available = true;
		}
		else if ( (data.getName().indexOf("MY COMPANY") != -1) )
		{
			Pattern pName = Pattern.compile("(\\d{4}).+님\\s+");
			Matcher mName = pName.matcher(message);
			Pattern pMoney = Pattern.compile("(\\d*,*\\d*,*\\d*,*\\d)원");
			Matcher mMoney = pMoney.matcher(message);
			Pattern pDate = Pattern.compile("([\\d]{2}[/][\\d]{2})");
			Matcher mDate = pDate.matcher(message);
			Pattern pMemo = Pattern.compile("\\d*,*\\d*,*\\d*,*\\d원\\s+(.+$)");	// ???원 뒤에
			Matcher mMemo = pMemo.matcher(message);
			
			if (mName.find())
			{
				for (int i=0; i<mName.groupCount(); i++) 
				{
					data.setName(data.getName() + "(" + mName.group(1) + ")");
				}
			}
			else
			{
				available = false;
				return;
			}
			
			if (mMoney.find()) 
			{
				for (int i=0; i<mMoney.groupCount(); i++) 
				{
					data.setMoney((mMoney.group(1).replaceAll(",", "")));
				}
			}
			else
			{
				available = false;
				return;
			}
			
			Calendar calendar = Calendar.getInstance();
			if (date != null && date.length() > 0)
			{
				data.setDate(date);
			} 
			else if (mDate.find()) 
			{
				for (int i=0; i<mDate.groupCount(); i++) 
				{
					data.setDate(calendar.get(Calendar.YEAR)+(mDate.group(1).replaceAll("/", "")));
				}
			}
			else
			{
				data.setDate(BDUtil.getDateDB(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH)+1, calendar.get(Calendar.DAY_OF_MONTH)));
			}
			
			if (mMemo.find()) 
			{
				for (int i=0; i<mMemo.groupCount(); i++) 
				{
					data.setMemo1((mMemo.group(1)));
					data.setMemo2((mMemo.group(1)));
					data.setMemo3((mMemo.group(1)));
					data.setMemo4((mMemo.group(1)));
				}
			}
			else
			{
				available = false;
				return;
			}
			
			available = true;
		}
		else if ( (data.getName().indexOf("동양") != -1) )
		{
			/*
			 * [동양]01/22 05:59 85**-**11-702*출금80,000기업/한우값 잔액16,102,243
			 * [동양]05/21 18:15 708-71-10****전액출금29,430 우리/서방현대 잔액100,000
			 * [동양]01/23 18:03 020-71-08***3전액출금99,990 삼성화0103 잔액1,919,374
				[동양]07/18 09:34 706-71-03***6출금250,000잔액63,583 --- 그냥출금
				
				[동양]01/20 11:28 115-71-00***7출금110,000신한/이*원 잔액216,191
				
				[동양]01/20 19:47 084-71-03***6삼성체크카드28,000산들해（송 잔액87,321
			 */
			Pattern pName = Pattern.compile("\\d{1,2}:\\d{1,2}\\s+(.+)전액출금");
			Matcher mName = pName.matcher(message);
			Pattern pName2 = Pattern.compile("\\d{1,2}:\\d{1,2}\\s+(.+)출금");
			Matcher mName2 = pName2.matcher(message);
			Pattern pName3 = Pattern.compile("\\d{1,2}:\\d{1,2}\\s+(.+)체크카드");
			Matcher mName3 = pName3.matcher(message);
			Pattern pMoney = Pattern.compile("출금(\\d*,*\\d*,*\\d*,*\\d)");
			Matcher mMoney = pMoney.matcher(message);
			Pattern pMoney2 = Pattern.compile("카드(\\d*,*\\d*,*\\d*,*\\d)");
			Matcher mMoney2 = pMoney2.matcher(message);
			Pattern pDate = Pattern.compile("([\\d]{2}[/][\\d]{2})");
			Matcher mDate = pDate.matcher(message);
			Pattern pMemo = Pattern.compile("출금\\d*,*\\d*,*\\d*,*\\d(.+)\\s+잔액");
			Matcher mMemo = pMemo.matcher(message);
			Pattern pMemo3 = Pattern.compile("카드\\d*,*\\d*,*\\d*,*\\d(.+)\\s+잔액");
			Matcher mMemo3 = pMemo3.matcher(message);
			Pattern pMemo2 = Pattern.compile("출금\\d*,*\\d*,*\\d*,*\\d잔액");
			Matcher mMemo2 = pMemo2.matcher(message);
			
			if (mName.find())
			{
				for (int i=0; i<mName.groupCount(); i++) 
				{
					data.setName(data.getName() + "(" + mName.group(1).replace("-", "") + ")");
				}
			}
			else if (mName2.find())
			{
				for (int i=0; i<mName2.groupCount(); i++) 
				{
					data.setName(data.getName() + "(" + mName2.group(1).replace("-", "") + ")");
				}
			}
			else if (mName3.find())
			{
				for (int i=0; i<mName3.groupCount(); i++) 
				{
					data.setName(data.getName() + "(" + mName3.group(1).replace("-", "").substring(0, mName3.group(1).replace("-", "").length()-2) + ")");
				}
			}
			else
			{
				available = false;
				return;
			}
			
			if (mMoney.find()) 
			{
				for (int i=0; i<mMoney.groupCount(); i++) 
				{
					data.setMoney((mMoney.group(1).replaceAll(",", "")));
				}
			}
			else if (mMoney2.find()) 
			{
				for (int i=0; i<mMoney2.groupCount(); i++) 
				{
					data.setMoney((mMoney2.group(1).replaceAll(",", "")));
				}
			}
			else
			{
				available = false;
				return;
			}
			
			Calendar calendar = Calendar.getInstance();
			if (date != null && date.length() > 0)
			{
				data.setDate(date);
			} 
			else if (mDate.find()) 
			{
				for (int i=0; i<mDate.groupCount(); i++) 
				{
					data.setDate(calendar.get(Calendar.YEAR)+(mDate.group(1).replaceAll("/", "")));
				}
			}
			else
			{
				data.setDate(BDUtil.getDateDB(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH)+1, calendar.get(Calendar.DAY_OF_MONTH)));
			}
			
			if (mMemo2.find()) 
			{
				data.setMemo1("현금 출금");
				data.setMemo2("현금 출금");
				data.setMemo3("현금 출금");
				data.setMemo4("현금 출금");
				
				smsType = BDConstents.OUT_ATM_SMS;
			}
			else if (mMemo.find()) 
			{
				for (int i=0; i<mMemo.groupCount(); i++) 
				{
					data.setMemo1((mMemo.group(1)));
					data.setMemo2((mMemo.group(1)));
					data.setMemo3((mMemo.group(1)));
					data.setMemo4((mMemo.group(1)));
				}
			}
			else if (mMemo3.find()) 
			{
				for (int i=0; i<mMemo3.groupCount(); i++) 
				{
					data.setMemo1((mMemo3.group(1)));
					data.setMemo2((mMemo3.group(1)));
					data.setMemo3((mMemo3.group(1)));
					data.setMemo4((mMemo3.group(1)));
				}
			}
			else
			{
				available = false;
				return;
			}
			
			available = true;
		}
		else if ( (data.getName().indexOf("농협NH체크카드") != -1))
		{
			Pattern pName = Pattern.compile("(\\d\\*\\d\\*)");
			Matcher mName = pName.matcher(message);
			Pattern pMoney = Pattern.compile("(\\d*,*\\d*,*\\d*,*\\d)원");
			Matcher mMoney = pMoney.matcher(message);
			Pattern pDate = Pattern.compile("([\\d]{2}[/][\\d]{2})");
			Matcher mDate = pDate.matcher(message);
//			Pattern pMemo = Pattern.compile("출금\\s*\\d*,*\\d*,*\\d*,*\\d\\s+(.+)\\s+잔액");
//			Matcher mMemo = pMemo.matcher(message);
			
			if (mName.find())
			{
				for (int i=0; i<mName.groupCount(); i++) 
				{
					data.setName(data.getName() + "(" + mName.group(1) + ")");
				}
			}
			else
			{
				available = false;
				return;
			}
			
			if (mMoney.find()) 
			{
				for (int i=0; i<mMoney.groupCount(); i++) 
				{
					data.setMoney((mMoney.group(1).replaceAll(",", "")));
				}
			}
			else
			{
				available = false;
				return;
			}
			
			Calendar calendar = Calendar.getInstance();
			if (date != null && date.length() > 0)
			{
				data.setDate(date);
			} 
			else if (mDate.find()) 
			{
				for (int i=0; i<mDate.groupCount(); i++) 
				{
					data.setDate(calendar.get(Calendar.YEAR)+(mDate.group(1).replaceAll("/", "")));
				}
			}
			else
			{
				data.setDate(BDUtil.getDateDB(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH)+1, calendar.get(Calendar.DAY_OF_MONTH)));
			}
			
//			if (mMemo.find()) 
//			{
//				for (int i=0; i<mMemo.groupCount(); i++) 
//				{
					data.setMemo1(("내용 없음"));
					data.setMemo2(("내용 없음"));
					data.setMemo3(("내용 없음"));
					data.setMemo4(("내용 없음"));
//				}
//			}
//			else
//			{
//				originalParsing();
//			}
			
			available = true;
		}
		else if ( (data.getName().indexOf("NH체크") != -1))
		{
			/*
			 * [NH체크승인]
				5,000원
				김지애님(6*5*)
				08/10 10:28
				잔액:1,970원
				흥덕온누리약국
				
				[NH체크승인]
				10,000원
				김지애님(6*5*)
				01/22 12:28
				잔액:184,540원
				무봤나촌닭
			 */
			Pattern pName = Pattern.compile("(\\d\\*\\d\\*)");
			Matcher mName = pName.matcher(message);
			Pattern pMoney = Pattern.compile("(\\d*,*\\d*,*\\d*,*\\d)원");
			Matcher mMoney = pMoney.matcher(message);
			Pattern pDate = Pattern.compile("([\\d]{2}[/][\\d]{2})");
			Matcher mDate = pDate.matcher(message);
			Pattern pMemo = Pattern.compile("\\d{1,2}:\\d{1,2}\\s+[잔액:-*\\d*,*\\d*,*\\d*,*\\d원\\s+]*(.+$)");
			Matcher mMemo = pMemo.matcher(message);
			
			if (mName.find())
			{
				for (int i=0; i<mName.groupCount(); i++) 
				{
					data.setName(data.getName() + "(" + mName.group(1) + ")");
				}
			}
			else
			{
				available = false;
				return;
			}
			
			if (mMoney.find()) 
			{
				for (int i=0; i<mMoney.groupCount(); i++) 
				{
					data.setMoney((mMoney.group(1).replaceAll(",", "")));
				}
			}
			else
			{
				available = false;
				return;
			}
			
			Calendar calendar = Calendar.getInstance();
			if (date != null && date.length() > 0)
			{
				data.setDate(date);
			} 
			else if (mDate.find()) 
			{
				for (int i=0; i<mDate.groupCount(); i++) 
				{
					data.setDate(calendar.get(Calendar.YEAR)+(mDate.group(1).replaceAll("/", "")));
				}
			}
			else
			{
				data.setDate(BDUtil.getDateDB(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH)+1, calendar.get(Calendar.DAY_OF_MONTH)));
			}
			
			if (mMemo.find()) 
			{
				for (int i=0; i<mMemo.groupCount(); i++) 
				{
					data.setMemo1(mMemo.group(1));
					data.setMemo2(mMemo.group(1));
					data.setMemo3(mMemo.group(1));
					data.setMemo4(mMemo.group(1));
				}
			}
			else
			{
				available = false;
				return;
			}
			
			available = true;
		}
		else if ( (data.getName().indexOf("SC은행") != -1))
		{
			/*
			 * SC은행210214**13 리틀브라운 4,000출금 잔액916,823 0805 11:19
			   SC은행606204**33 파리바게뜨구리 23,000출금 잔액29,638 0802 22:26
			   
			   SC은행108205**76
				１１번가＿１５
				2,000출금
				0123 10:30
			 */
			Pattern pName = Pattern.compile("SC은행(.{10})");
			Matcher mName = pName.matcher(message);
			Pattern pMoney = Pattern.compile("(\\d*,*\\d*,*\\d*,*\\d)출금\\s+");
			Matcher mMoney = pMoney.matcher(message);
			Pattern pDate = Pattern.compile("(\\d{4})\\s*\\d{2}:\\d{2}");
			Matcher mDate = pDate.matcher(message);
			Pattern pMemo = Pattern.compile("\\d\\s+(.+)\\s+\\d*,*\\d*,*\\d*,*\\d출금\\s+");
			Matcher mMemo = pMemo.matcher(message);
			
			if (mName.find())
			{
				for (int i=0; i<mName.groupCount(); i++) 
				{
					data.setName("SC은행" + "(" + mName.group(1) + ")");
				}
			}
			else
			{
				available = false;
				return;
			}
			
			if (mMoney.find()) 
			{
				for (int i=0; i<mMoney.groupCount(); i++) 
				{
					data.setMoney((mMoney.group(1).replaceAll(",", "")));
				}
			}
			else
			{
				available = false;
				return;
			}
			
			Calendar calendar = Calendar.getInstance();
			if (date != null && date.length() > 0)
			{
				data.setDate(date);
			} 
			else if (mDate.find()) 
			{
				for (int i=0; i<mDate.groupCount(); i++) 
				{
					data.setDate(calendar.get(Calendar.YEAR)+(mDate.group(1).replaceAll("/", "")));
				}
			}
			else
			{
				data.setDate(BDUtil.getDateDB(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH)+1, calendar.get(Calendar.DAY_OF_MONTH)));
			}
			
			if (mMemo.find()) 
			{
				for (int i=0; i<mMemo.groupCount(); i++) 
				{
					data.setMemo1((mMemo.group(1)));
					data.setMemo2((mMemo.group(1)));
					data.setMemo3((mMemo.group(1)));
					data.setMemo4((mMemo.group(1)));
				}
			}
			else
			{
				available = false;
				return;
			}
			
			available = true;
		}
		else if ( (data.getName().equalsIgnoreCase("새마을금고") ) )
		{
			/*
			 * <새마을금고>382710**2 111우07 출금10,000 잔액100,000 07/25 19:54
			 * <새마을금고>900214**5[sms알림]출금170,400잔액4,150 8/5 21:24
			 */
			
			Pattern pName = Pattern.compile("<새마을금고>(.{10})");
			Matcher mName = pName.matcher(message);
			Pattern pMoney = Pattern.compile("출금(\\d*,*\\d*,*\\d*,*\\d)\\s*잔액");
			Matcher mMoney = pMoney.matcher(message);
			Pattern pDate = Pattern.compile("(\\d{1,2}/\\d{1,2})");
			Matcher mDate = pDate.matcher(message);
			Pattern pMemo = Pattern.compile("\\*\\d\\s*(.+)\\s*출금");
			Matcher mMemo = pMemo.matcher(message);
			
			if (mName.find())
			{
				for (int i=0; i<mName.groupCount(); i++) 
				{
					data.setName("새마을금고" + "(" + mName.group(1) + ")");
				}
			}
			else
			{
				available = false;
				return;
			}
			
			if (mMoney.find()) 
			{
				for (int i=0; i<mMoney.groupCount(); i++) 
				{
					data.setMoney((mMoney.group(1).replaceAll(",", "")));
				}
			}
			else
			{
				available = false;
				return;
			}
			
			Calendar calendar = Calendar.getInstance();
			if (date != null && date.length() > 0)
			{
				data.setDate(date);
			} 
			else if (mDate.find()) 
			{
				for (int i=0; i<mDate.groupCount(); i++) 
				{
					data.setDate(calendar.get(Calendar.YEAR)+(mDate.group(1).replaceAll("/", "")));
				}
			}
			else
			{
				data.setDate(BDUtil.getDateDB(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH)+1, calendar.get(Calendar.DAY_OF_MONTH)));
			}
			
			if (mMemo.find()) 
			{
				for (int i=0; i<mMemo.groupCount(); i++) 
				{
					data.setMemo1((mMemo.group(1)));
					data.setMemo2((mMemo.group(1)));
					data.setMemo3((mMemo.group(1)));
					data.setMemo4((mMemo.group(1)));
				}
			}
			else
			{
				available = false;
				return;
			}
			
			available = true;
		}
		else if ( (data.getName().equalsIgnoreCase("MG체크카드") ) )
		{
			/*
			 * MG체크카드(6*4*) 김민준님 3,400원승인(계좌잔액152,200원)08/17.16:19 씨유안양석수연현점
				MG체크카드(1*4*) 김기동님 16,400원승인(계좌잔액-9,002,720원)08/11.18:05 파리바게뜨
				
				MG체크카드(3*9*) 32,000원승인(계좌잔액64,260원)01/23.19:52 바우석쇠
			 */
			
			Pattern pName = Pattern.compile("\\((\\d\\*\\d\\*)\\)");
			Matcher mName = pName.matcher(message);
			Pattern pMoney = Pattern.compile("\\s+(\\d*,*\\d*,*\\d*,*\\d)원");
			Matcher mMoney = pMoney.matcher(message);
			Pattern pDate = Pattern.compile("(\\d{1,2}/\\d{1,2})");
			Matcher mDate = pDate.matcher(message);
			Pattern pMemo = Pattern.compile("\\d{1,2}:\\d{1,2}\\s+(.+$)");
			Matcher mMemo = pMemo.matcher(message);
			
			if (mName.find())
			{
				for (int i=0; i<mName.groupCount(); i++) 
				{
					data.setName("MG체크카드" + "(" + mName.group(1) + ")");
				}
			}
			else
			{
				available = false;
				return;
			}
			
			if (mMoney.find()) 
			{
				for (int i=0; i<mMoney.groupCount(); i++) 
				{
					data.setMoney((mMoney.group(1).replaceAll(",", "")));
				}
			}
			else
			{
				available = false;
				return;
			}
			
			Calendar calendar = Calendar.getInstance();
			if (date != null && date.length() > 0)
			{
				data.setDate(date);
			} 
			else if (mDate.find()) 
			{
				for (int i=0; i<mDate.groupCount(); i++) 
				{
					data.setDate(calendar.get(Calendar.YEAR)+(mDate.group(1).replaceAll("/", "")));
				}
			}
			else
			{
				data.setDate(BDUtil.getDateDB(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH)+1, calendar.get(Calendar.DAY_OF_MONTH)));
			}
			
			if (mMemo.find()) 
			{
				for (int i=0; i<mMemo.groupCount(); i++) 
				{
					data.setMemo1((mMemo.group(1)));
					data.setMemo2((mMemo.group(1)));
					data.setMemo3((mMemo.group(1)));
					data.setMemo4((mMemo.group(1)));
				}
			}
			else
			{
				available = false;
				return;
			}
			
			available = true;
		}
		else if ( (data.getName().equalsIgnoreCase("전북") ) )
		{
			/*
			 * [전북]####139
				출금500
				잔액147,123
				08/29 10:51
				SMS수수료(출금)
			 */
			
			Pattern pName = Pattern.compile("\\[전북\\](.+)\\s+출금");
			Matcher mName = pName.matcher(message);
			Pattern pMoney = Pattern.compile("출금(\\d*,*\\d*,*\\d*,*\\d)\\s+잔액");
			Matcher mMoney = pMoney.matcher(message);
			Pattern pDate = Pattern.compile("(\\d{1,2}/\\d{1,2})");
			Matcher mDate = pDate.matcher(message);
			Pattern pMemo = Pattern.compile("\\d{1,2}:\\d{1,2}\\s+(.+$)");
			Matcher mMemo = pMemo.matcher(message);
			
			if (mName.find())
			{
				for (int i=0; i<mName.groupCount(); i++) 
				{
					data.setName("전북" + "(" + mName.group(1).replaceAll("#", "") + ")");
				}
			}
			else
			{
				available = false;
				return;
			}
			
			if (mMoney.find()) 
			{
				for (int i=0; i<mMoney.groupCount(); i++) 
				{
					data.setMoney((mMoney.group(1).replaceAll(",", "")));
				}
			}
			else
			{
				available = false;
				return;
			}
			
			Calendar calendar = Calendar.getInstance();
			if (date != null && date.length() > 0)
			{
				data.setDate(date);
			} 
			else if (mDate.find()) 
			{
				for (int i=0; i<mDate.groupCount(); i++) 
				{
					data.setDate(calendar.get(Calendar.YEAR)+(mDate.group(1).replaceAll("/", "")));
				}
			}
			else
			{
				data.setDate(BDUtil.getDateDB(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH)+1, calendar.get(Calendar.DAY_OF_MONTH)));
			}
			
			if (mMemo.find()) 
			{
				for (int i=0; i<mMemo.groupCount(); i++) 
				{
					data.setMemo1((mMemo.group(1)));
					data.setMemo2((mMemo.group(1)));
					data.setMemo3((mMemo.group(1)));
					data.setMemo4((mMemo.group(1)));
				}
			}
			else
			{
				available = false;
				return;
			}
			
			available = true;
		}
		else if ( (data.getName().equalsIgnoreCase("Citi") ) )
		{
			/*
			 * Citi 08/21 18:02 350-10***-262-01 출금 19,855 잔액 369,701 ＳＫ브로드밴드
			 * 
			 * Citi
				03/22 22:28
				536-01***-267-01
				출금 89,000
				적요
				수원북문점새마을
			 */
			
			Pattern pName = Pattern.compile("\\d{1,2}:\\d{1,2}\\s+(.+)\\s+출금");
			Matcher mName = pName.matcher(message);
			Pattern pMoney = Pattern.compile("출금\\s+(\\d*,*\\d*,*\\d*,*\\d)\\s+");
			Matcher mMoney = pMoney.matcher(message);
			Pattern pDate = Pattern.compile("(\\d{1,2}/\\d{1,2})");
			Matcher mDate = pDate.matcher(message);
			Pattern pMemo = Pattern.compile("잔액\\s+-*\\d*,*\\d*,*\\d*,*\\d\\s+(.+$)");
			Matcher mMemo = pMemo.matcher(message);
			Pattern pMemo2 = Pattern.compile("출금\\s+\\d*,*\\d*,*\\d*,*\\d\\s+(.+$)");
			Matcher mMemo2 = pMemo2.matcher(message);
			
			if (mName.find())
			{
				for (int i=0; i<mName.groupCount(); i++) 
				{
					data.setName("Citi" + "(" + mName.group(1).replaceAll("-", "") + ")");
				}
			}
			else
			{
				available = false;
				return;
			}
			
			if (mMoney.find()) 
			{
				for (int i=0; i<mMoney.groupCount(); i++) 
				{
					data.setMoney((mMoney.group(1).replaceAll(",", "")));
				}
			}
			else
			{
				available = false;
				return;
			}
			
			Calendar calendar = Calendar.getInstance();
			if (date != null && date.length() > 0)
			{
				data.setDate(date);
			} 
			else if (mDate.find()) 
			{
				for (int i=0; i<mDate.groupCount(); i++) 
				{
					data.setDate(calendar.get(Calendar.YEAR)+(mDate.group(1).replaceAll("/", "")));
				}
			}
			else
			{
				data.setDate(BDUtil.getDateDB(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH)+1, calendar.get(Calendar.DAY_OF_MONTH)));
			}
			
			if (mMemo.find()) 
			{
				for (int i=0; i<mMemo.groupCount(); i++) 
				{
					data.setMemo1((mMemo.group(1)));
					data.setMemo2((mMemo.group(1)));
					data.setMemo3((mMemo.group(1)));
					data.setMemo4((mMemo.group(1)));
				}
			}
			else if (mMemo2.find()) 
			{
				for (int i=0; i<mMemo2.groupCount(); i++) 
				{
					data.setMemo1((mMemo2.group(1)));
					data.setMemo2((mMemo2.group(1)));
					data.setMemo3((mMemo2.group(1)));
					data.setMemo4((mMemo2.group(1)));
				}
			}
			else
			{
				available = false;
				return;
			}
			
			available = true;
		}
		else if ( (data.getName().equalsIgnoreCase("현대스위스저축은행")) || (data.getName().equalsIgnoreCase("현대스위스2저축은행")) )
		{
			/*
			 * 현대스위스2저축은행(4*7*) 이아름님.56,000원.일시불.승인.09/06.16:56:55.어승생승마장
			 */
			
			Pattern pName = Pattern.compile("(\\(\\d\\*\\d\\*\\))");
			Matcher mName = pName.matcher(message);
			Pattern pMoney = Pattern.compile("(\\d*,*\\d*,*\\d*,*\\d)원");
			Matcher mMoney = pMoney.matcher(message);
			Pattern pDate = Pattern.compile("(\\d{1,2}/\\d{1,2})");
			Matcher mDate = pDate.matcher(message);
			Pattern pMemo = Pattern.compile("\\d{1,2}:\\d{1,2}\\.(.+$)");
			Matcher mMemo = pMemo.matcher(message);
			
			if (mName.find())
			{
				for (int i=0; i<mName.groupCount(); i++) 
				{
					data.setName("현대스위스저축은행" + mName.group(1));
				}
			}
			else
			{
				available = false;
				return;
			}
			
			if (mMoney.find()) 
			{
				for (int i=0; i<mMoney.groupCount(); i++) 
				{
					data.setMoney((mMoney.group(1).replaceAll(",", "")));
				}
			}
			else
			{
				available = false;
				return;
			}
			
			Calendar calendar = Calendar.getInstance();
			if (date != null && date.length() > 0)
			{
				data.setDate(date);
			} 
			else if (mDate.find()) 
			{
				for (int i=0; i<mDate.groupCount(); i++) 
				{
					data.setDate(calendar.get(Calendar.YEAR)+(mDate.group(1).replaceAll("/", "")));
				}
			}
			else
			{
				data.setDate(BDUtil.getDateDB(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH)+1, calendar.get(Calendar.DAY_OF_MONTH)));
			}
			
			if (mMemo.find()) 
			{
				for (int i=0; i<mMemo.groupCount(); i++) 
				{
					data.setMemo1((mMemo.group(1)));
					data.setMemo2((mMemo.group(1)));
					data.setMemo3((mMemo.group(1)));
					data.setMemo4((mMemo.group(1)));
				}
			}
			else
			{
				available = false;
				return;
			}
			
			available = true;
		}
		else if ( (data.getName().equalsIgnoreCase("KDB산업은행") ) )
		{
			/*
			 * 
				KDB산업은행(9*6*) 이*정님
				6,210원.승인(계좌잔액4,359,504원)
				05/09.12:39
				(주)이마트양산
			 */
			
			Pattern pName = Pattern.compile("(\\d{1,}\\*{1,}\\d{1,})");
			Matcher mName = pName.matcher(message);
			Pattern pMoney = Pattern.compile("(\\d*,*\\d*,*\\d*,*\\d)원");
			Matcher mMoney = pMoney.matcher(message);
			Pattern pDate = Pattern.compile("(\\d{1,2}/\\d{1,2})");
			Matcher mDate = pDate.matcher(message);
			Pattern pMemo = Pattern.compile("\\d{1,2}:\\d{1,2}\\s+(.+$)");
			Matcher mMemo = pMemo.matcher(message);
			
			if (mName.find())
			{
				for (int i=0; i<mName.groupCount(); i++) 
				{
					data.setName("KDB" + "(" + mName.group(1) + ")" );
				}
			}
			else
			{
				available = false;
				return;
			}
			
			if (mMoney.find()) 
			{
				for (int i=0; i<mMoney.groupCount(); i++) 
				{
					data.setMoney((mMoney.group(1).replaceAll(",", "")));
				}
			}
			else
			{
				available = false;
				return;
			}
			
			Calendar calendar = Calendar.getInstance();
			if (mDate.find()) 
			{
				for (int i=0; i<mDate.groupCount(); i++) 
				{
					data.setDate(calendar.get(Calendar.YEAR)+(mDate.group(1).replaceAll("/", "")));
				}
				
				available = true;
			}
			else if (date != null && date.length() > 0)
			{
				data.setDate(date);
			}
			else
			{
				data.setDate(BDUtil.getDateDB(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH)+1, calendar.get(Calendar.DAY_OF_MONTH)));
				//originalParsing();
			}
			
			if (mMemo.find()) 
			{
				for (int i=0; i<mMemo.groupCount(); i++) 
				{
					data.setMemo1((mMemo.group(1)));
					data.setMemo2((mMemo.group(1)));
					data.setMemo3((mMemo.group(1)));
					data.setMemo4((mMemo.group(1)));
				}
			}
			else
			{
				available = false;
				return;
			}
			
			available = true;
		}
		else if ( (data.getName().equalsIgnoreCase("KDB") ) )
		{
			/*
			 * 
				(KDB)020****3325
				출금
				180,000원
				홍길동
				잔액217,750원 16:47
				
				(KDB)박수지님
				020****2588
				출금
				50,600원
				(주)이니시스
				19:48
			 */
			
			Pattern pName = Pattern.compile("(\\d{1,}\\*{1,}\\d{1,})");
			Matcher mName = pName.matcher(message);
			Pattern pMoney = Pattern.compile("(\\d*,*\\d*,*\\d*,*\\d)원");
			Matcher mMoney = pMoney.matcher(message);
//			Pattern pDate = Pattern.compile("(\\d{1,2}/\\d{1,2})");
//			Matcher mDate = pDate.matcher(message);
			Pattern pMemo = Pattern.compile("\\d*,*\\d*,*\\d*,*\\d원\\s+(.+\\s*.+)\\s+잔액");
			Matcher mMemo = pMemo.matcher(message);
			Pattern pMemo2 = Pattern.compile("\\d*,*\\d*,*\\d*,*\\d원\\s+(.+\\s*.+)\\s+\\d{1,2}:\\d{1,2}");
			Matcher mMemo2 = pMemo2.matcher(message);
			
			if (mName.find())
			{
				for (int i=0; i<mName.groupCount(); i++) 
				{
					data.setName("KDB" + "(" + mName.group(1) + ")" );
				}
			}
			else
			{
				available = false;
				return;
			}
			
			if (mMoney.find()) 
			{
				for (int i=0; i<mMoney.groupCount(); i++) 
				{
					data.setMoney((mMoney.group(1).replaceAll(",", "")));
				}
			}
			else
			{
				available = false;
				return;
			}
			
			Calendar calendar = Calendar.getInstance();
//			if (mDate.find()) 
//			{
//				for (int i=0; i<mDate.groupCount(); i++) 
//				{
//					data.setDate(calendar.get(Calendar.YEAR)+(mDate.group(1).replaceAll("/", "")));
//				}
//				
//				available = true;
//			}
//			else 
			if (date != null && date.length() > 0)
			{
				data.setDate(date);
			}
			else
			{
				data.setDate(BDUtil.getDateDB(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH)+1, calendar.get(Calendar.DAY_OF_MONTH)));
				//originalParsing();
			}
			
			if (mMemo.find()) 
			{
				for (int i=0; i<mMemo.groupCount(); i++) 
				{
					data.setMemo1((mMemo.group(1)));
					data.setMemo2((mMemo.group(1)));
					data.setMemo3((mMemo.group(1)));
					data.setMemo4((mMemo.group(1)));
				}
			}
			else if (mMemo2.find()) 
			{
				for (int i=0; i<mMemo2.groupCount(); i++) 
				{
					data.setMemo1((mMemo2.group(1)));
					data.setMemo2((mMemo2.group(1)));
					data.setMemo3((mMemo2.group(1)));
					data.setMemo4((mMemo2.group(1)));
				}
			}
			else
			{
				available = false;
				return;
			}
			
			available = true;
		}
		else if ( (data.getName().equalsIgnoreCase("대우증권") ) )
		{
			/*
				[대우증권]08/30[18:40],210-20-114**** 출금100,000잔액100,000
			 */
			
			Pattern pName = Pattern.compile(",(.{1,8}-.{1,8}-.{1,8})\\s+");
			Matcher mName = pName.matcher(message);
			Pattern pMoney = Pattern.compile("출금\\s*(\\d*,*\\d*,*\\d*,*\\d)");
			Matcher mMoney = pMoney.matcher(message);
//			Pattern pDate = Pattern.compile("(\\d{1,2}/\\d{1,2})");
//			Matcher mDate = pDate.matcher(message);
//			Pattern pMemo = Pattern.compile("\\d*,*\\d*,*\\d*,*\\d원\\s+(.+\\s?.+)\\s+잔액");
//			Matcher mMemo = pMemo.matcher(message);
			
			if (mName.find())
			{
				for (int i=0; i<mName.groupCount(); i++) 
				{
					data.setName("대우증권" + "(" + mName.group(1).replaceAll("-", "") + ")" );
				}
			}
			else
			{
				available = false;
				return;
			}
			
			if (mMoney.find()) 
			{
				for (int i=0; i<mMoney.groupCount(); i++) 
				{
					data.setMoney((mMoney.group(1).replaceAll(",", "")));
				}
			}
			else
			{
				available = false;
				return;
			}
			
			Calendar calendar = Calendar.getInstance();
//			if (mDate.find()) 
//			{
//				for (int i=0; i<mDate.groupCount(); i++) 
//				{
//					data.setDate(calendar.get(Calendar.YEAR)+(mDate.group(1).replaceAll("/", "")));
//				}
//				
//				available = true;
//			}
//			else 
			if (date != null && date.length() > 0)
			{
				data.setDate(date);
			}
			else
			{
				data.setDate(BDUtil.getDateDB(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH)+1, calendar.get(Calendar.DAY_OF_MONTH)));
			}
			
//			if (mMemo.find()) 
//			{
//				for (int i=0; i<mMemo.groupCount(); i++) 
//				{
					data.setMemo1("내용 없음");
					data.setMemo2("내용 없음");
					data.setMemo3("내용 없음");
					data.setMemo4("내용 없음");
//				}
//			}
//			else
//			{
//				originalParsing();
//			}
			
			available = true;
		}
		
		
		if (data.getName() == null || data.getName().equalsIgnoreCase(""))
		{
			SmsOutMoney5 som5 = new SmsOutMoney5(data, message, date, smsType, checkcreditFlag);
			this.data = som5.getData();
			this.smsType = som5.getSmsType();
			this.available = som5.getAvailable();
		}
		if (data.getDate() == null || data.getDate().equalsIgnoreCase(""))
		{
			SmsOutMoney5 som5 = new SmsOutMoney5(data, message, date, smsType, checkcreditFlag);
			this.data = som5.getData();
			this.smsType = som5.getSmsType();
			this.available = som5.getAvailable();
		}
		if (data.getMoney() == null || data.getMoney().equalsIgnoreCase(""))
		{
			SmsOutMoney5 som5 = new SmsOutMoney5(data, message, date, smsType, checkcreditFlag);
			this.data = som5.getData();
			this.smsType = som5.getSmsType();
			this.available = som5.getAvailable();
		}
		if ( (data.getMemo1() == null) || (data.getMemo1().equalsIgnoreCase("")) 
				&& ( (data.getMemo2() == null) || (data.getMemo2().equalsIgnoreCase("")) )
				&& ( (data.getMemo3() == null) || (data.getMemo3().equalsIgnoreCase("")) )
				&& ( (data.getMemo4() == null) || (data.getMemo4().equalsIgnoreCase("")) ) )
		{
			SmsOutMoney5 som5 = new SmsOutMoney5(data, message, date, smsType, checkcreditFlag);
			this.data = som5.getData();
			this.smsType = som5.getSmsType();
			this.available = som5.getAvailable();
		}
		if (data.getName() == null || data.getName().equalsIgnoreCase("") 
				|| data.getDate() == null || data.getDate().equalsIgnoreCase("") 
				|| data.getMoney() == null || data.getMoney().equalsIgnoreCase("")
				|| ( data.getMemo1() == null || data.getMemo1().equalsIgnoreCase("") 
				&& data.getMemo2() == null || data.getMemo2().equalsIgnoreCase("")
				&& data.getMemo3() == null || data.getMemo3().equalsIgnoreCase("")
				&& data.getMemo4() == null || data.getMemo4().equalsIgnoreCase("") ) )
		{
			this.available = false;
			return;
		}
	}
}
